package edu.info.manager.dao;

import edu.info.manager.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teas = new Teacher[5];
    public boolean addTeacher(Teacher teacher) {
        int index = -1;
        for (int i = 0; i < teas.length; i++) {
            Teacher tea = teas[i];
            if(tea == null){
                index = i;
                break;
            }
        }
        if(index == -1){
            return false;
        }
        else{
            teas[index] = teacher;
            return true;
        }
    }

    public Teacher[] findAllTeachers() {

        return teas;
    }

    public void deleteTeacherById(String id) {
        int index = getIndex(id);
        teas[index] = null;
    }

    private int getIndex(String id){
        int index = -1;
        for (int i = 0; i < teas.length; i++) {
            if(teas[i]!= null && teas[i].getId().equals(id)){
                index = i;
                break;
            }
        }

        return index;
    }

    public void updateTeacherById(String id, Teacher teacher) {
        int index = getIndex(id);
        teas[index] = teacher;
    }
}
